package com.sdy.resdir.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sdy.auth.client.service.SsoService;
import com.sdy.common.model.Response;
import com.sdy.resdir.biz.service.RdIpImpleOrderService;
import com.sdy.resdir.biz.util.DeCodeUtil;
import com.sdy.resdir.biz.vo.IpImpleOrderInfoVo;
import com.sdy.resdir.biz.vo.IpImpleOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sdy.mvc.controller.BaseController;

import javax.servlet.http.HttpServletRequest;


/**
 * <p>
 * ip实施工单 前端控制器
 * </p>
 *
 * @author cgj
 * @since 2019-12-17
 */
@Slf4j
@RestController
@SuppressWarnings("unchecked")
@RequestMapping("/rdIpImpleOrder")
@Api(tags = "IP实施工单")
public class RdIpImpleOrderController extends BaseController {

    @Autowired
    private RdIpImpleOrderService rdIpImpleOrderService;
    @Autowired
    private SsoService ssoService;


    @ApiOperation(value = "IP实施工单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appName", value = "自建系统名称模糊查询"),
            @ApiImplicitParam(name = "ip", value = "IP地址模糊查询"),
            @ApiImplicitParam(name = "state", value = "实时状态 0-待实施  1-实施完成")
    })
    @GetMapping("/ipImplementationOrderPageList")
    public Response ipImplementationOrderPageList(Page page, String appName, String ip, Integer state, HttpServletRequest request) throws Exception {
        appName = DeCodeUtil.decodeParam(appName);
        ip = DeCodeUtil.decodeParam(ip);
        Integer userId = ssoService.getUserId(request);
        IPage<IpImpleOrderVo> rdIpImpleOrderPage = rdIpImpleOrderService.ipImpleOrderPageList(page, appName, ip, state, userId);
        return Response.success(rdIpImpleOrderPage);
    }

    @ApiOperation(value = "IP实施工单详情")
    @ApiImplicitParam(name = "orderId", value = "实施工单ID")
    @GetMapping("/ipImplementationOrderInfo")
    public Response ipImplementationOrderInfo(Integer orderId) throws Exception {
        IpImpleOrderInfoVo orderInfo = rdIpImpleOrderService.ipImpleOrderInfo(orderId);
        return Response.success(orderInfo);
    }

    @ApiOperation(value = "IP实施工单--实施完成")
    @ApiImplicitParam(name = "orderId", value = "实施工单ID")
    @GetMapping("/implementationDone")
    public Response implementationDone(Integer orderId) throws Exception {
        int impleOrderInfoDone = rdIpImpleOrderService.impleOrderInfoDone(orderId);
        return impleOrderInfoDone != 0 ? Response.success() : Response.error();
    }

}
